#include "HDRImageObject.hpp"

HDRImageObject::HDRImageObject(std::string fileName)
{
	//! Use FreeImage library to recognize image file type.
	FREE_IMAGE_FORMAT fileFormat = FreeImage_GetFileType( fileName.c_str() );

	//! Use FreeImage library to load data from image file.
	m_pHDRIBitmap = FreeImage_Load( fileFormat, fileName.c_str() );
}

HDRImageObject::~HDRImageObject()
{
	FreeImage_Unload(m_pHDRIBitmap);
}

const FIBITMAP* HDRImageObject::getHDRIBitmap() const
{
	return m_pHDRIBitmap;
}

const FIBITMAP* HDRImageObject::getToneMappedBitmap(TMO_ALGORITHM eAlgorithm) const
{
	FREE_IMAGE_TMO eTMO;

	switch(eAlgorithm)
	{
	case FATTAL_2002:
		eTMO = FITMO_FATTAL02;
		break;

	case DRAGO_2003:
		eTMO = FITMO_DRAGO03;
		break;

	case REINHARD_2005:
		eTMO = FITMO_REINHARD05;
		break;

	default:
		eTMO = FITMO_FATTAL02;
		break;
	}

	return FreeImage_ToneMapping(m_pHDRIBitmap, eTMO);
}

//EOF
